<template>
  <div class="wrapper">
    <router-link tag="div" to="/" class="header-back" v-show="showAbs">
      <div class="iconfont back-icon">&#xe658;</div>
    </router-link>
    <div class="header-title" v-show="!showAbs" :style="titleOpacity">
      <router-link tag="div" to="/" class="iconfont back-icon">&#xe658;</router-link>
      <h2>银杏湖乐园</h2>
    </div>
  </div>
</template>

<script>
export default {
  name: 'DetailHeader',
  data () {
    return {
      showAbs: true,
      titleOpacity: {
        opacity: 0
      }
    }
  },
  methods: {
    handleScroll () {
      const top = document.documentElement.scrollTop
      if (top > 36) {
        this.showAbs = false
        let opacity = top / 207
        opacity = opacity > 1 ? 1 : opacity
        this.titleOpacity = {
          opacity
        }
      } else {
        this.showAbs = true
      }
    }
  },
  activated () {
    window.addEventListener('scroll', this.handleScroll)
  },
  deactivated () {
    window.removeEventListener('scroll', this.handleScroll)
  }
}
</script>

<style lang="stylus" scoped>
  @import '~styles/variables.styl';
  .wrapper
    position relative
    .header-back
      position absolute
      top .1rem
      left .1rem
      width .71rem
      height .71rem
      border-radius 50%
      background-color rgba(0,0,0,.3)
      z-index 1
      .back-icon
        color #fff
        font-size .71rem
    .header-title
      position fixed
      top 0
      left 0
      right 0
      line-height .72rem
      display flex
      color #fff
      background-color $bgColor
      z-index 2
      .back-icon
        width .72rem
        font-size .72rem
      h2
        flex 1
        text-align center
        font-size .36rem
</style>
